package org.base.common.util;

import java.util.function.Function;
import java.util.function.Supplier;

public class GetUtils {

    public static <T, R> R get(T t, Function<T, R> func) {
        if (t != null) {
            return func.apply(t);
        }
        return null;
    }

    public static <T, R> R get(boolean condition, T t, Function<T, R> func) {
        if (condition) {
            return get(t, func);
        }
        return null;
    }

    public static <T, R> R safeGet(boolean condition, Supplier<T> supplier, Function<T, R> func) {
        if (condition) {
            return get(supplier.get(), func);
        }
        return null;
    }
}
